package com.sz.mes.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {


    public static String getPreDay() {

        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-HH-dd");

            Calendar calendar = Calendar.getInstance();
            int year=calendar.get(Calendar.YEAR);
            int month=calendar.get(Calendar.MONTH)+1;
            int today=calendar.get(Calendar.DAY_OF_MONTH);

            String day=year+"-"+month+"-"+today;

            Date date = sdf.parse(day);

            calendar.setTime(date);
            calendar.add(Calendar.DATE,-1);
            return sdf.format(calendar.getTime());

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static String getToDay() throws ParseException {

        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-HH-dd");
            Calendar calendar = Calendar.getInstance();

            int year=calendar.get(Calendar.YEAR);
            int month=calendar.get(Calendar.MONTH)+1;
            int today=calendar.get(Calendar.DAY_OF_MONTH);

            String day=year+"-"+month+"-"+today;

            Date date = sdf.parse(day);

            calendar.setTime(date);
            calendar.add(Calendar.DATE,0);

            return sdf.format(calendar.getTime());
        }catch (ParseException e) {
            e.printStackTrace();
        }


        return null;
    }

    public static String getAfterDay(String dateStr) throws Exception{
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-HH-dd");
            Calendar calendar = Calendar.getInstance();

            int year=calendar.get(Calendar.YEAR);
            int month=calendar.get(Calendar.MONTH)+1;
            int today=calendar.get(Calendar.DAY_OF_MONTH);

            String day=year+"-"+month+"-"+today;

            Date date = sdf.parse(day);

            calendar.setTime(date);
            calendar.add(Calendar.DATE,+1);

            return sdf.format(calendar.getTime());
        }catch (ParseException e) {
            e.printStackTrace();
        }


        return null;
    }

    public static String getPreWeek() {

        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-HH-dd");

            Calendar calendar = Calendar.getInstance();
            int year=calendar.get(Calendar.YEAR);
            int month=calendar.get(Calendar.MONTH)+1;
            int today=calendar.get(Calendar.DAY_OF_MONTH);

            String day=year+"-"+month+"-"+today;

            Date date = sdf.parse(day);

            calendar.setTime(date);
            calendar.add(Calendar.DATE,-7);
            return sdf.format(calendar.getTime());

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }
}
